export default {
  state: {
    // 默认地址
    chosenAddressId: 1,
    //  修改地址
    defaultAddress: {
      name: '陈',
      tel: '15237662486',
      addressDetail: '详情',
      areaCode: '110101',
      postalCode: '411523',
      isDefault: '',
    },
    // 被展示商品下单的收货人信息
    receiverInfo: JSON.parse(window.localStorage.getItem('receiverInfo')) || {}
  },
  mutations: {
    // 获取默认id
    defaultId (state) {
      state.chosenAddressId = JSON.parse(window.localStorage.getItem('setChosenAddressId'))
    },
    // 修改默认地址
    setDefaultAddress (state, val) {
      state.defaultAddress = val
    },
    // 动态修改默认收货人
    receiverInfo (state, val) {
      window.localStorage.setItem('receiverInfo', JSON.stringify(val))
      state.receiverInfo = JSON.parse(window.localStorage.getItem('receiverInfo'))
      // 持久化存储

    }
  },
  actions: {
    actDefaultAddress (context, val) {
      context.commit('setDefaultAddress', val)
    }
  },
}